package com.loklok.confuse.model;

import com.intellij.ide.fileTemplates.impl.UrlUtil;
import com.intellij.util.ExceptionUtil;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * @Classname TypeSettingsStorage
 * @Description
 * @Date 2023/8/29 21:37
 * @author by wangchangjiu
 */
public class ConfuseConfig {

    public static String loadDefaultConfig(){
        try {
            // 从配置文件中加载配置
            String json = UrlUtil.loadText(ConfuseConfig.class.getResource("/codeGenerateConfig/default.json"));
            return json;
        } catch (Exception e) {
            ExceptionUtil.rethrow(e);
        }
        return null;
    }


    public static class LoadFullCodeConfig implements Serializable {

        private String serviceName;

        private List<LoadCodeConfigItem> items;

        public String getServiceName() {
            return serviceName;
        }

        public void setServiceName(String serviceName) {
            this.serviceName = serviceName;
        }

        public List<LoadCodeConfigItem> getItems() {
            return items;
        }

        public void setItems(List<LoadCodeConfigItem> items) {
            this.items = items;
        }
    }

    public static class LoadRaisedCodeConfig implements Serializable {

        private String url;

        private List<LoadCodeConfigItem> items;


        public List<LoadCodeConfigItem> getItems() {
            return items;
        }

        public void setItems(List<LoadCodeConfigItem> items) {
            this.items = items;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

    }

    public static class LoadCodeConfigItem implements Serializable {
        private String type;

        private List<String> methods;
        private String loadPath;

        private String className;

        private Set<String> classNames;

        public boolean configIsController(){
            return "controller".equalsIgnoreCase(this.getType());
        }
        public boolean configIsRequest(){
            return "request".equalsIgnoreCase(this.getType());
        }
        public boolean configIsVo(){
            return "vo".equalsIgnoreCase(this.getType());
        }

        public boolean configIsMethod(){
            return "method".equalsIgnoreCase(this.getType());
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getLoadPath() {
            return loadPath;
        }

        public void setLoadPath(String loadPath) {
            this.loadPath = loadPath;
        }

        public String getClassName() {
            return className;
        }

        public void setClassName(String className) {
            this.className = className;
        }

        public Set<String> getClassNames() {
            return classNames;
        }

        public void setClassNames(Set<String> classNames) {
            this.classNames = classNames;
        }

        public List<String> getMethods() {
            return methods;
        }

        public void setMethods(List<String> methods) {
            this.methods = methods;
        }
    }
}
